package pruebaicpc;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class volumen2 {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        short no = sc.nextShort();
        while (no > 0) {
            short[] intervalos = new short[no];
            for (int i = 0; i < intervalos.length; i++) {
                intervalos[i] = sc.nextShort();
            }
            short inicial = sc.nextShort();
            short volMax = sc.nextShort();

            Queue<Short> lista = new LinkedList<Short>();
            lista.add(inicial);

            for (int i = 0; i < intervalos.length; i++) {
                int intervalo = intervalos[i];
                Queue<Short> nuevaLista = new LinkedList<Short>();
                while (!lista.isEmpty()) {
                    short no_aux = lista.poll();
                    short suma = (short) (no_aux + intervalo);
                    short resta = (short) (no_aux - intervalo);
                    if (suma <= volMax && !nuevaLista.contains(suma)) {
                        nuevaLista.add(suma);
                    }
                    if (resta >= 0 && !nuevaLista.contains(resta)) {
                        nuevaLista.add(resta);
                    }
                }
                lista = nuevaLista;
            }
            int mayor = -1;
            while (!lista.isEmpty()) {
                short actual = lista.poll();
                if (actual > mayor) {
                    mayor = actual;
                }
            }
            System.out.println(mayor);
            no = sc.nextShort();
        }
    }
}
